package com.zzxy.spring.aspect;

import org.aopalliance.intercept.Joinpoint;
import org.aspectj.apache.bcel.generic.RET;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class MyAspectJ {

    @Pointcut("execution(* com.zzxy.spring.service.impl.*.*(..))")
    public void myPointcut(){


    }

    @Before("myPointcut()")
    public void myBefore(JoinPoint joinpoint){
        System.out.println("before method :" +joinpoint.getSignature().getName() );
        System.out.println("my before....");
   }

   @After("myPointcut()")
   public void myAfter(JoinPoint joinPoint){
       System.out.println("after method :"+joinPoint.getSignature().getName());
       System.out.println("my after....");
   }

   @Around("myPointcut()")
   public Object myAround(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("before around :"+pjp.getSignature().getName());
        Object obj = pjp.proceed();
       System.out.println("after around :"+pjp.getSignature().getName());
       return obj;
   }

   @AfterReturning(value = "myPointcut()",returning = "ret")
   public void  myAfterReturning(JoinPoint joinPoint,Object ret){

       System.out.println("after returning method :"+joinPoint.getSignature().getName()+"- return : " + ret);

   }


   @AfterThrowing(value = "myPointcut()", throwing="e")
   public void myThrowing(JoinPoint joinPoint, Throwable e){
       System.out.println("my throwing"+ e.getMessage());

   }

}
